/**
 * Title: AbsBaseAdapter.java
 * Description:
 * Copyright: Copyright (c) 2008
 * Company:深圳彩讯科技有限公司
 * Author 罗旭东 (hi@luoxudong.com)
 * Date 2013-8-14 上午9:24:17
 * Version 1.0 
 */
package com.luoxudong.phonenumber.ui.adapters;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/** 
 * ClassName: AbsBaseAdapter 
 * Description:activity中adapter的抽象基类
 * Create by 罗旭东
 * Date 2013-8-14 上午9:24:17 
 */
public abstract class AbsBaseAdapter<T> extends BaseAdapter{
	/**
	 * 内容
	 */
	protected List<T> dataList = null;
	
	/**
	 * 上下文
	 */
	protected Context context = null;
	
	/**
	 * 布局
	 */
	protected LayoutInflater inflater= null;

	public AbsBaseAdapter(Context context, List<T> list){
		this.context = context;
		this.dataList = list;
		
		inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	
	/**
	 * 
	 * @description:设置内容
	 * @param list 内容list
	 * @throws
	 */
	public void setList(List<T> list) {
		this.dataList = list;
	}
	
	/**
	 * 
	 * @description: 获取内容
	 * @return 内容list
	 * @throws
	 */
	public List<T> getList() {
		return dataList;
	}

	/**
	 * 
	 * @description:在开始位置添加内容
	 * @param list 需要添加的内容
	 * @throws
	 */
	public void appendToBottomList(List<T> list) {
		if (list == null) {
			return;
		}
		
		if (dataList == null)
		{
			dataList = new ArrayList<T>();
		}
		
		dataList.addAll(list);
		//notifyDataSetChanged();
	}

	/**
	 * 
	 * @description:在尾部添加内容
	 * @param list
	 * @throws
	 */
	public void appendToTopList(List<T> list) {
		if (list == null) {
			return;
		}
		
		if (dataList == null)
		{
			dataList = new ArrayList<T>();
		}
		
		dataList.addAll(0, list);
		//notifyDataSetChanged();
	}

	/**
	 * 
	 * @description:清除内容
	 * @throws
	 */
	public void clear() {
		
		if (dataList == null)
		{
			return;
		}
		
		dataList.clear();
		//notifyDataSetChanged();
	}

	@Override
	public int getCount() {
		
		if (dataList == null)
		{
			return 0;
		}
		
		return dataList.size();
	}

	@Override
	public T getItem(int position) {
		if (dataList == null || (position > dataList.size() - 1)) {
			return null;
		}
		
		return dataList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return getItemView(position, convertView, parent);
	}
	
	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		return super.getDropDownView(position, convertView, parent);
	}
	
	protected abstract View getItemView(int position, View convertView, ViewGroup parent);
}
